from manimlib import*

def square():
    return RegularPolygon(4,fill_opacity=1).rotate(PI/4)
def get_left(obj):
    a=obj.get_center()+LEFT*obj.get_width()/2
    return a[0]
def get_right(obj):
    a=obj.get_center()-LEFT*obj.get_width()/2
    return a[0]
def get_up(obj):
    a=obj.get_center()+UP*obj.get_height()/2
    return a[1]
def get_down(obj):
    a=obj.get_center()-UP*obj.get_height()/2
    return a[1]
def on(obj,back):
    a=obj.get_x()<get_right(back)
    b=obj.get_x()>get_left(back)
    c=obj.get_y()<get_up(back)
    d=obj.get_y()>get_down(back)
    return a and b and c and d

def color_by_picture(grid,image):
    for t in grid:
        if on(t,image):
            t.set_color(rgb_to_color(image.point_to_rgb(t.get_center())))
        else:
            t.set_color("#333333")

class video(Scene):
    def construct(self):
        image_list=["word","excel"]
        image_vgroup=Group(*[ImageMobject(name) for name in image_list]).set_height(8)
        self.t=0
        single_object=Tex("\\pi").scale(3)
        grid=single_object.get_grid(int(8/single_object.get_height()*2.5),int(image_vgroup.get_width()/single_object.get_width()*2.5),buff=0).set_height(8)
        def updategrid(obj,dt):
            self.t+=dt
            color_by_picture(obj,image_vgroup[int(self.t)])
        grid.add_updater(updategrid)
        self.add(grid)
        self.wait(2)

class picture(Scene):
    def construct(self):
        image=ImageMobject("share").set_height(8)
        grid=Tex("\\mathrm{UP}").scale(3)
        G=grid.get_grid(int(8/grid.get_height()*5),int(image.get_width()/grid.get_width()*5),buff=0).set_height(8)
        self.add(G)
        for m in G:
            for t in m:
                if on(t,image):
                    t.set_color(rgb_to_color(image.point_to_rgb(t.get_center())))
                else:
                    t.set_color("#333333")
        self.wait(1/60)